package com.dahaiwuliang.code.controller;

import com.dahaiwuliang.code.server.ArcTypeService;
import com.dahaiwuliang.code.server.ArticleService;
import com.dahaiwuliang.code.util.Consts;
import com.dahaiwuliang.code.util.HTMLUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * 根路径及其他请求处理
 */
@Controller
public class IndexController {

    @Autowired
    private ArcTypeService arcTypeService;

    @Autowired
    private ArticleService articleService;

    /**
     * 首页
     */
    @RequestMapping("/")
    public ModelAndView index(){
        ModelAndView mav = new ModelAndView();
        mav.setViewName("index");
        //类型的html代码
        List arcTypleList = arcTypeService.listAll(Sort.Direction.ASC,"sort");
        mav.addObject("arcTypeStr", HTMLUtil.getArcTypeStr("all",arcTypleList));
        //资源列表
        Map<String,Object> map = articleService.list("all",1, Consts.PAGE_SIZE);
        mav.addObject("articleList",map.get("data"));
        //分页html代码
        mav.addObject("pageStr",HTMLUtil.getPagation("/article/all",Integer.parseInt(String.valueOf(map.get("count"))),1,"该分类还没有数据..."));
        return mav;
    }
    @RequestMapping("/buyVIP")
    public  String  buyVIP(){
        return  "buyVIP";
    }

    @RequestMapping("/fbzyzjf")
    public  String  fbzyzjf(){
        return  "fbzyzjf";
    }
}
